

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="python" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="python" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>QUANTAXIS.QAData.QADataStruct &mdash; QUANTAXIS 1.0.39 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> QUANTAXIS
          

          
          </a>

          
            
            
              <div class="version">
                1.0.39
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">QUANTAXIS</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>QUANTAXIS.QAData.QADataStruct</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for QUANTAXIS.QAData.QADataStruct</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding:utf-8</span>
<span class="c1">#</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016-2018 yutiansut/QUANTAXIS</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in all</span>
<span class="c1"># copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<span class="c1"># SOFTWARE.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">定义一些可以扩展的数据结构</span>

<span class="sd">方便序列化/相互转换</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">platform</span>
<span class="kn">import</span> <span class="nn">statistics</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">webbrowser</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="k">import</span> <span class="n">copy</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">lru_cache</span><span class="p">,</span> <span class="n">partial</span><span class="p">,</span> <span class="n">reduce</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyecharts</span> <span class="k">import</span> <span class="n">Kline</span>

<span class="kn">from</span> <span class="nn">QUANTAXIS.QAData.base_datastruct</span> <span class="k">import</span> <span class="n">_quotation_base</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAData.data_fq</span> <span class="k">import</span> <span class="n">QA_data_stock_to_fq</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAData.data_resample</span> <span class="k">import</span> <span class="n">QA_data_tick_resample</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAData.proto</span> <span class="k">import</span> <span class="n">stock_day_pb2</span>  <span class="c1"># protobuf import</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAData.proto</span> <span class="k">import</span> <span class="n">stock_min_pb2</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAFetch.QATdx</span> <span class="k">import</span> <span class="n">QA_fetch_get_stock_realtime</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAIndicator</span> <span class="k">import</span> <span class="n">EMA</span><span class="p">,</span> <span class="n">HHV</span><span class="p">,</span> <span class="n">LLV</span><span class="p">,</span> <span class="n">SMA</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAUtil</span> <span class="k">import</span> <span class="p">(</span><span class="n">DATABASE</span><span class="p">,</span> <span class="n">QA_util_log_info</span><span class="p">,</span>
                              <span class="n">QA_util_random_with_topic</span><span class="p">,</span>
                              <span class="n">QA_util_to_json_from_pandas</span><span class="p">,</span>
                              <span class="n">QA_util_to_pandas_from_json</span><span class="p">,</span> <span class="n">trade_date_sse</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAUtil.QADate</span> <span class="k">import</span> <span class="n">QA_util_to_datetime</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAUtil.QAParameter</span> <span class="k">import</span> <span class="n">FREQUENCE</span><span class="p">,</span> <span class="n">MARKET_TYPE</span>


<div class="viewcode-block" id="QA_DataStruct_Stock_day"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_day">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Stock_day</span><span class="p">(</span><span class="n">_quotation_base</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>

<span class="sd">        股票日线数据</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">init_data_by_df</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;stock_day&#39;</span><span class="p">,</span> <span class="n">if_fq</span><span class="o">=</span><span class="s1">&#39;bfq&#39;</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        # 🛠 todo dtype=stock_day 和 QA_DataStruct_Stock_day 类的名字是对应的 不变的不需要指定 ，容易出错，建议改成常量 ❌</span>
<span class="sd">        :param init_data_by_df:  DataFrame 类型的数据，包含了数据，用来初始化这个类</span>
<span class="sd">        :param dtype:  stock_day 🛠 todo 改成常量</span>
<span class="sd">        :param if_fq:  是否复权</span>
<span class="sd">        &#39;&#39;&#39;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">init_data_by_df</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">if_fq</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">init_data_by_df</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢Error init_data_by_df is not kind of DataFrame type !&quot;</span><span class="p">)</span>


        <span class="c1">#根据 根据前一天收盘价 补齐 当天最高最低价</span>
        <span class="k">if</span> <span class="s1">&#39;high_limit&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;high_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">close</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.0002</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="k">if</span> <span class="s1">&#39;low_limit&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;low_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">close</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.0002</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="c1">#根据 根据今天收盘价 补齐 明天最高最低价</span>
        <span class="k">if</span> <span class="s1">&#39;next_day_high_limit&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;next_day_high_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">close</span> <span class="o">+</span> <span class="mf">0.0002</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="k">if</span> <span class="s1">&#39;next_day_low_limit&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;next_day_low_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">close</span> <span class="o">+</span> <span class="mf">0.0002</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

    <span class="c1">#抽象类继承</span>
<div class="viewcode-block" id="QA_DataStruct_Stock_day.choose_db"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_day.choose_db">[docs]</a>    <span class="k">def</span> <span class="nf">choose_db</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_day</span></div>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Stock_day with </span><span class="si">{}</span><span class="s1"> securities &gt;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))</span>
    <span class="fm">__str__</span> <span class="o">=</span> <span class="fm">__repr__</span>

    <span class="c1">#前复权</span>
<div class="viewcode-block" id="QA_DataStruct_Stock_day.to_qfq"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_day.to_qfq">[docs]</a>    <span class="k">def</span> <span class="nf">to_qfq</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="ow">is</span> <span class="s1">&#39;bfq&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="s1">&#39;qfq&#39;</span>
                <span class="k">return</span> <span class="bp">self</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">20</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span>
                    <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">QA_data_stock_to_fq</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;code&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">x</span><span class="p">]),</span> <span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))),</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;qfq&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">new</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">QA_data_stock_to_fq</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;qfq&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;none support type for qfq Current type is: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span></div>

    <span class="c1">#后复权</span>
<div class="viewcode-block" id="QA_DataStruct_Stock_day.to_hfq"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_day.to_hfq">[docs]</a>    <span class="k">def</span> <span class="nf">to_hfq</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="ow">is</span> <span class="s1">&#39;bfq&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="s1">&#39;hfq&#39;</span>
                <span class="k">return</span> <span class="bp">self</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">QA_data_stock_to_fq</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;code&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">x</span><span class="p">],</span> <span class="s1">&#39;hfq&#39;</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))),</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;hfq&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;none support type for qfq Current type is: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">high_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s1">&#39;涨停价&#39;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">high_limit</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">low_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s1">&#39;跌停价&#39;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">low_limit</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">next_day_low_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s2">&quot;明日跌停价&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">next_day_low_limit</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">next_day_high_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s2">&quot;明日涨停价&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">next_day_high_limit</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">preclose</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">preclose</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">price_chg</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">preclose</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">preclose</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span></div>


<div class="viewcode-block" id="QA_DataStruct_Stock_min"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_min">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Stock_min</span><span class="p">(</span><span class="n">_quotation_base</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;stock_min&#39;</span><span class="p">,</span> <span class="n">if_fq</span><span class="o">=</span><span class="s1">&#39;bfq&#39;</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">if_fq</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;preclose&#39;</span> <span class="ow">in</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">ix</span><span class="p">[:,</span> <span class="p">[</span>
                    <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;volume&#39;</span><span class="p">,</span> <span class="s1">&#39;preclose&#39;</span><span class="p">,</span> <span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">]]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">ix</span><span class="p">[:,</span> <span class="p">[</span>
                    <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;volume&#39;</span><span class="p">,</span> <span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">]]</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">e</span>

        <span class="k">if</span> <span class="s1">&#39;high_limit&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;high_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">close</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.0002</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="k">if</span> <span class="s1">&#39;low_limit&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;low_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">close</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.0002</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dtype</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="n">if_fq</span>

    <span class="c1">#抽象类继承</span>
<div class="viewcode-block" id="QA_DataStruct_Stock_min.choose_db"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_min.choose_db">[docs]</a>    <span class="k">def</span> <span class="nf">choose_db</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_min</span></div>


    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Stock_Min with </span><span class="si">{}</span><span class="s1"> securities &gt;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))</span>
    <span class="fm">__str__</span> <span class="o">=</span> <span class="fm">__repr__</span>

<div class="viewcode-block" id="QA_DataStruct_Stock_min.to_qfq"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_min.to_qfq">[docs]</a>    <span class="k">def</span> <span class="nf">to_qfq</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="ow">is</span> <span class="s1">&#39;bfq&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="s1">&#39;qfq&#39;</span>
                <span class="k">return</span> <span class="bp">self</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">20</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">QA_DataStruct_Stock_min</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">QA_data_stock_to_fq</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;code&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">x</span><span class="p">]),</span> <span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)))</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
                <span class="n">data</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="s1">&#39;qfq&#39;</span>
                <span class="k">return</span> <span class="n">data</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">QA_DataStruct_Stock_min</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">QA_data_stock_to_fq</span><span class="p">))</span>
                <span class="k">return</span> <span class="n">data</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;none support type for qfq Current type is:</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_min.to_hfq"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_min.to_hfq">[docs]</a>    <span class="k">def</span> <span class="nf">to_hfq</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="ow">is</span> <span class="s1">&#39;bfq&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="s1">&#39;hfq&#39;</span>
                <span class="k">return</span> <span class="bp">self</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">QA_DataStruct_Stock_min</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">QA_data_stock_to_fq</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;code&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">x</span><span class="p">],</span> <span class="s1">&#39;hfq&#39;</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)))</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
                <span class="n">data</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="s1">&#39;hfq&#39;</span>
                <span class="k">return</span> <span class="n">data</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;none support type for qfq Current type is:</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">high_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s1">&#39;涨停价&#39;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">high_limit</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">low_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s1">&#39;跌停价&#39;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">low_limit</span></div>


<div class="viewcode-block" id="QA_DataStruct_Future_day"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Future_day">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Future_day</span><span class="p">(</span><span class="n">_quotation_base</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;future_day&#39;</span><span class="p">,</span> <span class="n">if_fq</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="s1">&#39;future_day&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">ix</span><span class="p">[:,</span> <span class="p">[</span>
            <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;trade&#39;</span><span class="p">,</span> <span class="s1">&#39;position&#39;</span><span class="p">,</span> <span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">]]</span>

    <span class="c1">#抽象类继承</span>
<div class="viewcode-block" id="QA_DataStruct_Future_day.choose_db"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Future_day.choose_db">[docs]</a>    <span class="k">def</span> <span class="nf">choose_db</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">future_day</span></div>


    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Future_day with </span><span class="si">{}</span><span class="s1"> securities &gt;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))</span>
    <span class="fm">__str__</span> <span class="o">=</span> <span class="fm">__repr__</span></div>


<div class="viewcode-block" id="QA_DataStruct_Future_min"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Future_min">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Future_min</span><span class="p">(</span><span class="n">_quotation_base</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    struct for future</span>
<span class="sd">    &quot;&quot;&quot;</span>


    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;future_min&#39;</span><span class="p">,</span> <span class="n">if_fq</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
        <span class="c1"># 🛠todo  期货分钟数据线的维护， 暂时用日线代替分钟线</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="s1">&#39;future_day&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">ix</span><span class="p">[:,</span> <span class="p">[</span>
            <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;trade&#39;</span><span class="p">,</span> <span class="s1">&#39;position&#39;</span><span class="p">,</span> <span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">]]</span>

    <span class="c1"># 抽象类继承</span>
<div class="viewcode-block" id="QA_DataStruct_Future_min.choose_db"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Future_min.choose_db">[docs]</a>    <span class="k">def</span> <span class="nf">choose_db</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">future_min</span></div>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Future_min with </span><span class="si">{}</span><span class="s1"> securities &gt;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))</span>
    <span class="fm">__str__</span> <span class="o">=</span> <span class="fm">__repr__</span></div>


<div class="viewcode-block" id="QA_DataStruct_Index_day"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Index_day">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Index_day</span><span class="p">(</span><span class="n">_quotation_base</span><span class="p">):</span>
    <span class="s1">&#39;自定义的日线数据结构&#39;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;index_day&#39;</span><span class="p">,</span> <span class="n">if_fq</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dtype</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="n">if_fq</span>
        <span class="c1">#self.mongo_coll = eval(</span>
        <span class="c1">#    &#39;DATABASE.{}&#39;.format(self.type))</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    def __add__(self,DataStruct):</span>
<span class="sd">        &#39;add func with merge list and reindex&#39;</span>
<span class="sd">        assert isinstance(DataStruct,QA_DataStruct_Index_day)</span>
<span class="sd">        if self.if_fq==DataStruct.if_fq:</span>
<span class="sd">            self.sync_status(pd.concat())</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># 抽象类继承</span>
<div class="viewcode-block" id="QA_DataStruct_Index_day.choose_db"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Index_day.choose_db">[docs]</a>    <span class="k">def</span> <span class="nf">choose_db</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">index_day</span></div>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Index_day with </span><span class="si">{}</span><span class="s1"> securities &gt;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">))</span>
    <span class="fm">__str__</span> <span class="o">=</span> <span class="fm">__repr__</span></div>


<div class="viewcode-block" id="QA_DataStruct_Index_min"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Index_min">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Index_min</span><span class="p">(</span><span class="n">_quotation_base</span><span class="p">):</span>
    <span class="s1">&#39;自定义的分钟线数据结构&#39;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;index_min&#39;</span><span class="p">,</span> <span class="n">if_fq</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dtype</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">if_fq</span> <span class="o">=</span> <span class="n">if_fq</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">ix</span><span class="p">[:,</span> <span class="p">[</span>
            <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;volume&#39;</span><span class="p">,</span> <span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">]]</span>
        <span class="c1">#self.mongo_coll = DATABASE.index_min</span>

    <span class="c1"># 抽象类继承</span>
<div class="viewcode-block" id="QA_DataStruct_Index_min.choose_db"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Index_min.choose_db">[docs]</a>    <span class="k">def</span> <span class="nf">choose_db</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">index_min</span></div>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Index_Min with </span><span class="si">%s</span><span class="s1"> securities &gt;&#39;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">)</span>

    <span class="fm">__str__</span> <span class="o">=</span> <span class="fm">__repr__</span></div>


<div class="viewcode-block" id="QA_DataStruct_Stock_block"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_block">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Stock_block</span><span class="p">():</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Stock_Block &gt;&#39;</span>

    <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">len</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;返回DataStruct的长度</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">block_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;返回所有的板块名</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">&#39;blockname&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">code</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;返回唯一的证券代码</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">code</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

<div class="viewcode-block" id="QA_DataStruct_Stock_block.show"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_block.show">[docs]</a>    <span class="k">def</span> <span class="nf">show</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;展示DataStruct</span>

<span class="sd">        Returns:</span>
<span class="sd">            dataframe -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_block.get_code"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_block.get_code">[docs]</a>    <span class="k">def</span> <span class="nf">get_code</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">code</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;getcode 获取某一只股票的板块</span>

<span class="sd">        Arguments:</span>
<span class="sd">            code {str} -- 股票代码</span>

<span class="sd">        Returns:</span>
<span class="sd">            DataStruct -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_block</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;code&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">code</span><span class="p">])</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_block.get_block"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_block.get_block">[docs]</a>    <span class="k">def</span> <span class="nf">get_block</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">_block_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;getblock 获取板块</span>

<span class="sd">        Arguments:</span>
<span class="sd">            _block_name {[type]} -- [description]</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_block</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;blockname&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">_block_name</span><span class="p">])</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_block.getdtype"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_block.getdtype">[docs]</a>    <span class="k">def</span> <span class="nf">getdtype</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dtype</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;getdtype</span>

<span class="sd">        Arguments:</span>
<span class="sd">            dtype {str} -- gn-概念/dy-地域/fg-风格/zs-指数</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_block</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">dtype</span><span class="p">])</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_block.get_price"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_block.get_price">[docs]</a>    <span class="k">def</span> <span class="nf">get_price</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">_block_name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;get_price</span>

<span class="sd">        Keyword Arguments:</span>
<span class="sd">            _block_name {[type]} -- [description] (default: {None})</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">_block_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">code</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;blockname&#39;</span><span class="p">]</span>
                                 <span class="o">==</span> <span class="n">_block_name</span><span class="p">]</span><span class="o">.</span><span class="n">code</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                <span class="c1"># try to get a datastruct package of lastest price</span>
                <span class="k">return</span> <span class="n">QA_fetch_get_stock_realtime</span><span class="p">(</span><span class="n">code</span><span class="p">)</span>

            <span class="k">except</span><span class="p">:</span>
                <span class="k">return</span> <span class="s2">&quot;Wrong Block Name! Please Check&quot;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">code</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">code</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">QA_fetch_get_stock_realtime</span><span class="p">(</span><span class="n">code</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="QA_DataStruct_Stock_transaction"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_transaction">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Stock_transaction</span><span class="p">():</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Stock Transaction</span>

<span class="sd">        Arguments:</span>
<span class="sd">            DataFrame {pd.Dataframe} -- [input is one/multi day transaction]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="s1">&#39;stock_transaction&#39;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span>
        <span class="k">if</span> <span class="s1">&#39;amount&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;vol&#39;</span> <span class="ow">in</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;amount&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">vol</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">price</span> <span class="o">*</span> <span class="mi">100</span>
            <span class="k">elif</span> <span class="s1">&#39;volume&#39;</span> <span class="ow">in</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;amount&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">volume</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">price</span> <span class="o">*</span> <span class="mi">100</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mongo_coll</span> <span class="o">=</span> <span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_transaction</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">buyorsell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the buy or sell towards 0--buy 1--sell 2--none</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            [pd.Series] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">buyorsell</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">price</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the deal price of tick transaction</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">price</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">vol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the deal volume of tick</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            pd.Series -- volume of transaction</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">volume</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">vol</span>

    <span class="n">volume</span> <span class="o">=</span> <span class="n">vol</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">date</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the date of transaction</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            pd.Series -- date of transaction</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">date</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">time</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the exact time of transaction(to minute level)</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            pd.Series -- till minute level </span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">time</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">datetime</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the datetime of transaction</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            pd.Series -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">datetime</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">order</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the order num of transaction/ for everyday change</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            pd.series -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">order</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return the transaction index</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">index</span>

    <span class="nd">@property</span>
    <span class="nd">@lru_cache</span><span class="p">()</span>
    <span class="k">def</span> <span class="nf">amount</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return current tick trading amount</span>

<span class="sd">        Decorators:</span>
<span class="sd">            lru_cache</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">amount</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    最新:IF(ISNULL(NEW),PRE,NEW);</span>
<span class="sd">    IF (ISNULL(RANGE_AVG_PRICE) OR RANGE_AVG_PRICE &lt;= 0)</span>
<span class="sd">    {</span>
<span class="sd">        IF (MARKETTYPE == 232 OR MARKETTYPE == 56 OR MARKETTYPE==64 OR MARKETTYPE==128 OR MARKETTYPE==168 OR MARKETTYPE==184 OR MARKETTYPE == 200 OR MARKETTYPE == 80 OR (VOL &gt; 1 AND VOL&lt;100))</span>
<span class="sd">        {</span>
<span class="sd">            b=SUBSAMEDAY(&amp;VOL) ;</span>
<span class="sd">            m=SUM(b*最新,0);</span>
<span class="sd">            均价:IF(m&gt;0,m/VOL,PRE);</span>
<span class="sd">        }</span>
<span class="sd">        ELSE IF(CODETYPE!=0 AND MONEY&gt;0)</span>
<span class="sd">        {</span>
<span class="sd">            IF(ISNULL(MONEY) OR ISNULL(VOL) OR VOL==0 OR MONEY==0)</span>
<span class="sd">                均价:PRE;</span>
<span class="sd">            ELSE IF(VOL==VOL[1] OR MONEY==MONEY[1])</span>
<span class="sd">                均价:均价[1];</span>
<span class="sd">            ELSE</span>
<span class="sd">                均价:MONEY/VOL;</span>
<span class="sd">        }</span>
<span class="sd">        ELSE IF (MARKETTYPE == 176)</span>
<span class="sd">        {</span>
<span class="sd">            b=SUBSAMEDAY(&amp;MONEY);</span>
<span class="sd">            m=SUM(b*最新,0);</span>
<span class="sd">            IF(m&gt;0)</span>
<span class="sd">                均价:m/MONEY;</span>
<span class="sd">        }</span>
<span class="sd">    }</span>
<span class="sd">    ELSE</span>
<span class="sd">    {</span>
<span class="sd">        均价:RANGE_AVG_PRICE;</span>
<span class="sd">    }</span>
<span class="sd">    DRAWGBK(MARKETTYPE==32 AND FORMATTIME(1)&lt;10 AND TRADETIME&gt;242),RGB(0,0,128);</span>
<span class="sd">    RETURN;</span>


<span class="sd">    hx_star;</span>
<span class="sd">    hx_star_p;</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_DataStruct_Stock_Transaction &gt;&#39;</span>

    <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span>

<div class="viewcode-block" id="QA_DataStruct_Stock_transaction.resample"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_transaction.resample">[docs]</a>    <span class="k">def</span> <span class="nf">resample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">type_</span><span class="o">=</span><span class="s1">&#39;1min&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;resample methods</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_min</span><span class="p">(</span><span class="n">QA_data_tick_resample</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">type_</span><span class="p">))</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_transaction.get_big_orders"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_transaction.get_big_orders">[docs]</a>    <span class="k">def</span> <span class="nf">get_big_orders</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bigamount</span><span class="o">=</span><span class="mi">1000000</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return big order</span>

<span class="sd">        Keyword Arguments:</span>
<span class="sd">            bigamount {[type]} -- [description] (default: {1000000})</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s1">&#39;amount&gt;=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">bigamount</span><span class="p">))</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_transaction.get_medium_order"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_transaction.get_medium_order">[docs]</a>    <span class="k">def</span> <span class="nf">get_medium_order</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lower</span><span class="o">=</span><span class="mi">200000</span><span class="p">,</span> <span class="n">higher</span><span class="o">=</span><span class="mi">1000000</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return medium </span>

<span class="sd">        Keyword Arguments:</span>
<span class="sd">            lower {[type]} -- [description] (default: {200000})</span>
<span class="sd">            higher {[type]} -- [description] (default: {1000000})</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s1">&#39;amount&gt;=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">lower</span><span class="p">))</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s1">&#39;amount&lt;=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">higher</span><span class="p">))</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_transaction.get_small_order"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_transaction.get_small_order">[docs]</a>    <span class="k">def</span> <span class="nf">get_small_order</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">smallamount</span><span class="o">=</span><span class="mi">200000</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;return small level order</span>

<span class="sd">        Keyword Arguments:</span>
<span class="sd">            smallamount {[type]} -- [description] (default: {200000})</span>

<span class="sd">        Returns:</span>
<span class="sd">            [type] -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s1">&#39;amount&lt;=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">smallamount</span><span class="p">))</span></div>

<div class="viewcode-block" id="QA_DataStruct_Stock_transaction.get_time"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_transaction.get_time">[docs]</a>    <span class="k">def</span> <span class="nf">get_time</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">start</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">end</span><span class="p">]</span></div></div>


<span class="k">class</span> <span class="nc">_realtime_base</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    realtime 基类</span>

<span class="sd">    主要字段有:</span>
<span class="sd">    code/name</span>
<span class="sd">    time</span>
<span class="sd">    open/high/low</span>

<span class="sd">    买卖报价队列:(不同的可能不一样 只提供list)</span>
<span class="sd">    ask_list[ask1_price/ask1_volume|ask2_price/ask2_volume|ask3_price/ask3_volume....]</span>
<span class="sd">    bid_list[bid1_price/bid1_volume|bid2_price/bid2_volume|bid3_price/bid3_volume....]</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">market_data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;转化成dict模式</span>

<span class="sd">        Arguments:</span>
<span class="sd">            market_data {[type]} -- [description]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">market_data</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span> <span class="o">=</span> <span class="n">market_data</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">market_data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span> <span class="o">=</span> <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">market_data</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">price</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;price&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">datetime</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">high</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">low</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">code</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">last_close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;last_close&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">cur_vol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;cur_vol&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid1</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid1&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid_vol1</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid_vol1&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid2&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid_vol2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid_vol2&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid3</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid3&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid_vol3</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid_vol3&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid4</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid4&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid_vol4</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid_vol4&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid5&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bid_vol5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;bid_vol5&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask1</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask1&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask_vol1</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask_vol1&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask2&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask_vol2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask_vol2&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask3</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask3&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask_vol3</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask_vol3&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask4</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask4&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask_vol4</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask_vol4&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask5&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ask_vol5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ask_vol5&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>


<div class="viewcode-block" id="QA_DataStruct_Stock_realtime"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_realtime">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Stock_realtime</span><span class="p">(</span><span class="n">_realtime_base</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">market_data</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">market_data</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span> <span class="o">=</span> <span class="n">market_data</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">market_data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">market_data</span> <span class="o">=</span> <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">market_data</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt; QA_REALTIME_STRUCT </span><span class="si">{}{}</span><span class="s1"> &gt;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">datetime</span><span class="p">)</span>

    <span class="c1"># @property</span>
    <span class="c1"># def ask_list(self):</span>
    <span class="c1">#     return self.market_data.ix[:, [&#39;ask1&#39;, &#39;ask_vol1&#39;, &#39;bid1&#39;, &#39;bid_vol1&#39;, &#39;ask2&#39;, &#39;ask_vol2&#39;,</span>
    <span class="c1">#                                    &#39;bid2&#39;, &#39;bid_vol2&#39;, &#39;ask3&#39;, &#39;ask_vol3&#39;, &#39;bid3&#39;, &#39;bid_vol3&#39;, &#39;ask4&#39;,</span>
    <span class="c1">#                                    &#39;ask_vol4&#39;, &#39;bid4&#39;, &#39;bid_vol4&#39;, &#39;ask5&#39;, &#39;ask_vol5&#39;, &#39;bid5&#39;, &#39;bid_vol5&#39;]]</span>

    <span class="c1"># @property</span>
    <span class="c1"># def bid_list(self):</span>
    <span class="c1">#     return self.market_data.ix[:, [&#39;bid1&#39;, &#39;bid_vol1&#39;, &#39;bid2&#39;, &#39;bid_vol2&#39;,  &#39;bid3&#39;, &#39;bid_vol3&#39;, &#39;bid4&#39;, &#39;bid_vol4&#39;, &#39;bid5&#39;, &#39;bid_vol5&#39;]]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        return a dataframe-type result</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">market_data</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ab_board</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;ask_bid board</span>
<span class="sd">        bid3 bid_vol3</span>
<span class="sd">        bid2 bid_vol2</span>
<span class="sd">        bid1 bid_vol1</span>
<span class="sd">        ===============</span>
<span class="sd">        price /cur_vol</span>
<span class="sd">        ===============</span>
<span class="sd">        ask1 ask_vol1</span>
<span class="sd">        ask2 ask_vol2</span>
<span class="sd">        ask3 ask_vol3</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s1">&#39;BID5 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">BID4 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">BID3 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">BID2 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">BID1 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">============</span><span class="se">\n</span><span class="s1">CURRENT </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">============</span><span class="se">\</span>
<span class="s1">        </span><span class="se">\n</span><span class="s1">ASK1 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">ASK2 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">ASK3 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">ASK4 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">ASK5 </span><span class="si">{}</span><span class="s1">  </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">TIME </span><span class="si">{}</span><span class="s1">  CODE </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bid5</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid_vol5</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid4</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid_vol4</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid3</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid_vol3</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid_vol2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bid_vol1</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">price</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cur_vol</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ask1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask_vol1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask_vol2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask3</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask_vol3</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask4</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask_vol4</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask5</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ask_vol5</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">datetime</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">code</span>
        <span class="p">)</span>

<div class="viewcode-block" id="QA_DataStruct_Stock_realtime.serialize"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_realtime.serialize">[docs]</a>    <span class="k">def</span> <span class="nf">serialize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;to_protobuf</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">pass</span></div></div>


<div class="viewcode-block" id="QA_DataStruct_Stock_realtime_series"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_realtime_series">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Stock_realtime_series</span><span class="p">():</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sr_series</span><span class="p">):</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sr_series</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">QA_DataStruct_Stock_realtime</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sr_series</span> <span class="o">=</span> <span class="n">sr_series</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sr_series</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sr_series</span> <span class="o">=</span> <span class="p">[</span>
                <span class="n">QA_DataStruct_Stock_realtime</span><span class="p">(</span><span class="n">sr</span><span class="p">)</span> <span class="k">for</span> <span class="n">sr</span> <span class="ow">in</span> <span class="n">sr_series</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">table</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">sr</span><span class="o">.</span><span class="n">_data</span> <span class="k">for</span> <span class="n">sr</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sr_series</span><span class="p">])</span></div>


<div class="viewcode-block" id="QA_DataStruct_Security_list"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Security_list">[docs]</a><span class="k">class</span> <span class="nc">QA_DataStruct_Security_list</span><span class="p">():</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="p">[</span><span class="s1">&#39;sse&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span>
            <span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">code</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">code</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">name</span>

<div class="viewcode-block" id="QA_DataStruct_Security_list.get_stock"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Security_list.get_stock">[docs]</a>    <span class="k">def</span> <span class="nf">get_stock</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ST_option</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span></div>

<div class="viewcode-block" id="QA_DataStruct_Security_list.get_index"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Security_list.get_index">[docs]</a>    <span class="k">def</span> <span class="nf">get_index</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span></div>

<div class="viewcode-block" id="QA_DataStruct_Security_list.get_etf"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAData.html#QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Security_list.get_etf">[docs]</a>    <span class="k">def</span> <span class="nf">get_etf</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, yutiansut.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'1.0.39',
            LANGUAGE:'python',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>